import java.awt.*; import java.awt.image.*; import javax.sound.midi.*; public class io12 extends Frame { Image img[] = new Image[100]; int index = 0; public io12() { // 花火のy位置 int y = 110; // 花火の大きさ int size = 4; // 花火の色 int r = 80, g = 80, b = 80; // アニメ用イメージ作成 for (int i = 0;i < 100;i++) { // フレーム用BufferedImageオブジェクト生成 img[i] = new BufferedImage(128, 128, BufferedImage.TYPE_INT_BGR); // フレーム描画用Graphics取得 Graphics gr = img[i].getGraphics(); gr.setColor(Color.black); gr.fillRect(0, 0, 128, 128); gr.setColor(new Color(64, 64, 64)); gr.fillRect(60, 108, 8, 16); // 打ち上げ初期 if (i < 20) { gr.setColor(new Color(r, g, b)); gr.fillOval(64 - size / 2, y - size / 2, size, size); y -= 2; } // 爆発直前の溜め if (i >= 20 && i < 30) { gr.setColor(new Color(r, g, b)); gr.fillOval(64 - size / 2, y - size / 2, size, size); y -= 1; } // 爆発の色 if (i == 30) { r = 192; g = 160; b = 144; } // 爆発 if (i >= 30 && i < 50) { gr.setColor(new Color(r, g, b)); gr.fillOval(64 - size / 2, y - size / 2, size, size); size += 2; } // 消滅 if (i >= 50 && i < 70) { gr.setColor(new Color(r, g, b)); gr.fillOval(64 - size / 2, y - size / 2, size, size); size += 1; r -= 2; g -= 2; b -= 2; } } // コンポーネントのサイズ設定 setSize(256, 256); // 可視状態に setVisible(true); Synthesizer syn = null; // MIDI再生準備 try { syn = MidiSystem.getSynthesizer(); syn.open(); } catch (Exception e) {} // アニメ再生 while (index < 100) { repaint(); // 再生するフレーム更新 index++; try { Thread.sleep(50); } catch (InterruptedException e) {} // 爆発音 if (index == 30) { syn.getChannels()[0].noteOn(30, 100); } if (index == 60) { syn.getChannels()[0].noteOff(30); } } // MIDIクローズ syn.close(); System.exit(0); } public void update(Graphics g){ paint(g); } public void paint(Graphics g){ // アニメ用イメージを拡大表示 g.drawImage(img[index], 0, 0, 256, 256, this); } public static void main(String args[]) { // アプリケーション生成 io12 app = new io12(); } }